clear all
set more off

use "data/raw/rainforest-sender-deidentified", clear 

* Classify private support
gen join = join_campaign=="Yes"
lab var join "Joined campaign"

* Drop pre-randomization attritters and flag post-randomization attriters
drop if !inlist(condition, "excuse", "noexcuse")

gen attrit = 0
replace attrit = 1 if join_campaign == "" | (join_campaign == "Yes" & post == "")
lab var attrit "Respondent attritted post-randomization"

* hispanic as an identifier as 
*drop if hispanic == ""

gen attention = screener=="Extremely interested,Not at all interested"
keep if attention
drop attention screener

* Generate outcome and treatment variables
gen posted = post=="Yes"
*replace posted = 1 if missing(post)
replace posted = . if missing(post)
lab var posted "Authorized Twitter post"
drop post 

gen excuse = condition=="excuse"
lab var excuse "Excuse condition"
gen noexcuse = condition=="noexcuse"
lab var noexcuse "No excuse condition"
drop condition

* Generate demographic and control variables
gen ind = party=="Independent"
lab var ind "Independent"
*drop party

gen partisan = .
replace partisan = 2 if liberal == "Very conservative"
replace partisan = 1 if liberal == "Conservative"
replace partisan = 0 if liberal == "Neither liberal nor conservative"
replace partisan = -1 if liberal == "Liberal"
replace partisan = -2 if liberal == "Very liberal"
label var partisan "Partisan leaning"

destring year, replace
gen age = 2021-year
lab var age "Age"
drop year

gen age2 = age^2
lab var age2 "Age squared"
gen hisp = hispanic=="Yes"
lab var hisp "Spanish, Hispanic, or Latino"
drop hispanic
gen male = sex == "Male"
lab var male "Male"
drop sex

lab var education "Education level"

gen white = race=="Caucasian/White"
lab var white "White"
lab var race "Race"

keep attrit join posted excuse noexcuse education race ind partisan age age2 hisp male white party 


save "data/working/rainforest-sender.dta", replace
exit,clear
